<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'post-form',
    'enableAjaxValidation' => true,
    'enableClientValidation' => true,
    'type' => 'horizontal',
    'clientOptions' => array(
        'validateOnSubmit' => true,
    ),
));
?>

<p class="help-block">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<?php echo $form->textFieldRow($model, 'post_title', array('class' => 'span5', 'maxlength' => 255)); ?>

<?php echo $form->textFieldRow($model, 'alias', array('class' => 'span5', 'maxlength' => 255)); ?>

<?php echo $form->textAreaRow($model, 'post_description', array('rows' => 6, 'cols' => 50, 'class' => 'span8')); ?>

<div class="control-group">

    <label class="control-label">Content</label>

    <div class="controls">
        <?php
        $this->widget('ext.tinymce.TinyMce', array(
            'model' => $model,
            'attribute' => 'post_content',
            'fileManager' => array(
                'class' => 'ext.elFinder.TinyMceElFinder',
                'connectorRoute' => 'filemanager/connector',
            ),
            'htmlOptions' => array(
                'rows' => 6,
                'cols' => 60,
            )
        ));
        ?>
    </div>

</div>


<ul class="nav nav-tabs">
    <li class="active">
        <a data-toggle="tab" href="#meta-tab">Meta data</a>
    </li>
    <?php if($this->module->isSupport($model->post_type, 'supportImage')) : ?>
    <li><a data-toggle="tab" href="#images-tab">Images</a></li>
    <?php endif; ?>

    <li>
        <a data-toggle="tab" href="#publish-tab">Publish</a>
    </li>
</ul>
<div class="tab-content">

    <div id="meta-tab" class="tab-pane active">
        <?php echo $form->textAreaRow($model, 'tags', array('class' => 'span8')); ?>

        <?php echo $form->textAreaRow($model, 'meta_keywords', array('class' => 'span8', 'maxlength' => 255)); ?>

        <?php echo $form->textAreaRow($model, 'meta_description', array('class' => 'span8', 'maxlength' => 255)); ?>
    </div>

    <?php if($this->module->isSupport($model->post_type, 'supportImage')) : ?>
    <div id="images-tab" class="tab-pane fade">
        <div class="control-group">
            <label class="control-label">Images</label>
            <div class="controls">
                <ul id="images">
                    <?php foreach($model->getImages() as $image) : ?>
                    <li>
                        <img src="<?php echo $image ?>" style="width:150px" />
                        <input type="hidden" name="image[]" value="<?php echo $image ?>" />
                        <a class="btn btn-link removeImage">Remove</a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Select image</label>
            <div class="controls">
                <?php $this->widget('application.extensions.elFinder.ImagePickerInput', array(
                    'name' => 'image',
                    'htmlOptions' => array(
                        'id' => 'imagewidget'
                    ),
                    'connectorRoute' => '/filemanager/connector',
                )) ?>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <div id="publish-tab" class="tab-pane fade">

        <?php echo $form->textFieldRow($model, 'parent_id', array('class' => 'span5')); ?>
        <?php echo $form->dropDownListRow($model, 'status', array(
            Post::STATUS_PUBLISH => 'Publish',
            Post::STATUS_DRAFT => 'Draft',
            Post::STATUS_ARCHIVE => 'Archive'
        ), array('class' => 'span5')); ?>
        <?php echo $form->checkBoxRow($model, 'sticky'); ?>
    </div>
</div>

<div class="form-actions">
    <?php
    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'submit',
        'type' => 'primary',
        'label' => $model->isNewRecord ? 'Create' : 'Save',
    ));
    ?>
</div>

<?php $this->endWidget(); ?>
<script>
    $(document).ready(function(){
        $(".removeImage").live("click", function(){
            $(this).closest("li").remove();
            return false;
        });

        $("#Post_post_title").keyup(function(){
            var Text = $(this).val();
            Text = Text.toLowerCase();
            Text = Text.replace(/[^a-zA-Z0-9]+/g,'-');
            $("#Post_alias").val(Text);
    });
    });
</script>